/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chainreaction;

import java.awt.Color;
import java.awt.Point;

/**
 *
 * @author Jordan
 */
public class Bomb {
    static final int DEF_MAX_RAD = 35; // default maximum radius of a bomb
    static final int DEF_RADIUS = 15;
    static final int DEF_SPECIAL_RAD = 5;

    public enum Type {
        Cherry (Color.RED, DEF_SPECIAL_RAD),
        Time (Color.BLUE, DEF_SPECIAL_RAD),
        Money (Color.ORANGE, DEF_SPECIAL_RAD),
        Standard (Color.WHITE, DEF_RADIUS);

        private Color typeColor;
        private double defRadius;
        Type(Color color, double rad) {
            this.typeColor = color;
            this.defRadius = rad;
        }

        public Color getColor() {
            return typeColor;
        }
        public double getDefaultRadius() {
            return this.defRadius;
        }
    }
    
    private Point location;
    private Point direction;
    private double radius, maxRadius, dRad;
    private boolean exploded;
    private long explosionID;

    private Bomb.Type type;

    public Bomb(int width, int height, Bomb.Type type) {
        double defRadius = type.getDefaultRadius();
        int randX = (int)(Math.random() * (width-(defRadius*2)) + defRadius);
        int randY = (int)(Math.random() * (height-(defRadius*2)) + defRadius);
        int randDx = Math.random() > 0.5 ? 1 : -1;
        int randDy = Math.random() > 0.5 ? 1 : -1;

        this.location = new Point(randX, randY);
        this.direction = new Point(randDx, randDy);
        this.radius = defRadius; // Set the radius to the starting radius
        this.dRad = 0;
        this.maxRadius = DEF_MAX_RAD;
        this.type = type;
    }

    public Bomb(int x, int y, int dRad, long explosionID) {
        this.location = new Point(x, y);
        this.direction = new Point(0,0);
        this.dRad = dRad;
        this.radius = DEF_RADIUS;
        this.maxRadius = DEF_MAX_RAD;
        this.explosionID = explosionID;
        this.type = Type.Standard;
    }

    public Point getLocation() {
        return location;
    }
    public Point getDirection() {
        return direction;
    }
    public int getRadius() {
        return (int)(radius);
    }
    public int getMaxRadius() {
        return (int)(maxRadius);
    }
    public long getExplosionID() {
        return explosionID;
    }
    public Bomb.Type getType() {
        return this.type;
    }
    public boolean exploding() {
        return dRad != 0;
    }
    public boolean exploded() {
        return exploded;
    }

    public void setDirection(Point p) {
        this.direction = p;
    }
    public void setMaxRadius(int r) {
        this.maxRadius = r;
    }

    public void tick() {
        if (!this.exploding()) {
            this.location.x += this.direction.x;
            this.location.y += this.direction.y;
        }

        // Explosion control
        if (radius >= maxRadius) {
            this.dRad = 0;
            this.exploded = true;
        }
        this.radius += this.dRad;
    }
    public void explode(long explosionID) {
        if (this.type == Type.Cherry)
            this.dRad = 2;
        else
            this.dRad = 0.75;
        this.explosionID = explosionID;
    }
}
